#include <autoconfig.h>
#include <stdio.h>
#include <string.h>
#include "port.h"
// #include "fpga-common.h"
#include "misc-if.h"
// #include "fpga-private.h"
#include "port.h"


#define INIT_BSP     (102)
#define LOAD_BSP_ENV (203)

extern int sys_setLCDBrightness(int brightness);
extern int sys_setBacklightTime(int backlightTime);
extern int sys_setBacklightAlwaysOn(void);


extern int imx287_getChargeState(int *chargeState1, int *chargeState2, int *externalPowerSupply);
extern int imx287_getBatteryPower(int *power1, int *power2);
extern int imx287_getTemperature(int *data);
extern int imx287_fpga_getTemperature(int *data);
extern int imx287_arm_getTemperature(int *data);
extern int imx287_get_temp_vol(float *data);

static struct misc_if com_if_imx287 = {
    // DEFAULT_MISC_IF,
    .name                      = "this-imx287",
    .pfun_getChargeState       = imx287_getChargeState,
    .pfun_getBatteryPower      = imx287_getBatteryPower,
    .pfun_getTemperature       = imx287_arm_getTemperature,
    .pfun_get_temp_vol         = imx287_get_temp_vol,
    .pfun_setLCDBrightness     = sys_setLCDBrightness,
    .pfun_setBacklightTime     = sys_setBacklightTime,
    .pfun_setBacklightAlwaysOn = sys_setBacklightAlwaysOn,
};

static struct misc_if com_if_imx287_fpga = {
    // DEFAULT_MISC_IF,
    .name                      = "this-imx287-fpga",
    .pfun_getChargeState       = imx287_getChargeState,
    .pfun_getBatteryPower      = imx287_getBatteryPower,
    .pfun_getTemperature       = imx287_fpga_getTemperature,  // 从FPGA读取温度
    .pfun_get_temp_vol         = imx287_get_temp_vol,
    .pfun_setLCDBrightness     = sys_setLCDBrightness,
    .pfun_setBacklightTime     = sys_setBacklightTime,
    .pfun_setBacklightAlwaysOn = sys_setBacklightAlwaysOn,
};

extern int imx6_getChargeState(int *chargeState1, int *chargeState2, int *externalPowerSupply);
extern int imx6_getBatteryPower(int *power1, int *power2);
extern int getBatteryPower(int *power1, int *power2);
extern int iio_getTemperature(int *data);
extern int imx6_get_temp_vol(float *data);

// int (*pfun_getTemperature)(int *data);


static struct misc_if com_if = {
    // DEFAULT_MISC_IF,
    .name                      = "this-common",
    .pfun_getChargeState       = imx6_getChargeState,
    .pfun_getBatteryPower      = imx6_getBatteryPower,
    .pfun_getTemperature       = iio_getTemperature,
    .pfun_get_temp_vol         = imx6_get_temp_vol,
    .pfun_setLCDBrightness     = sys_setLCDBrightness,
    .pfun_setBacklightTime     = sys_setBacklightTime,
    .pfun_setBacklightAlwaysOn = sys_setBacklightAlwaysOn,
};

static struct misc_if com_if_fpga = {
    // DEFAULT_MISC_IF,
    .name                      = "this-common-fpga",
    .pfun_getChargeState       = imx6_getChargeState,
    .pfun_getBatteryPower      = imx6_getBatteryPower,
    .pfun_getTemperature       = imx287_fpga_getTemperature,  // 从FPGA读取温度
    .pfun_get_temp_vol         = imx6_get_temp_vol,
    .pfun_setLCDBrightness     = sys_setLCDBrightness,
    .pfun_setBacklightTime     = sys_setBacklightTime,
    .pfun_setBacklightAlwaysOn = sys_setBacklightAlwaysOn,
};

static void __attribute__((constructor(INIT_BSP))) this_init()
{
    struct misc_if *pif;

    misc_if_register(&com_if);
    misc_if_register(&com_if_fpga);
    misc_if_register(&com_if_imx287);
    misc_if_register(&com_if_imx287_fpga);
}
